package com.stormrage.edu.dao.learn.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.learn.LeaStudentDao;
import com.stormrage.entity.learn.LeaStudent;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: LeaTermDaoImpl.java
 * @Package com.stormrage.edu.dao.learn.impl
 * @Description: 学员 Dao
 * @author www.stormragetech.com
 * @date 2016年4月17日
 * @version V1.0
 */
@Repository
public class LeaStudentDaoImpl extends MysBaseDao implements LeaStudentDao {

	private static final Logger logger = LoggerFactory.getLogger(LeaStudentDaoImpl.class);

	@Override
	public Integer create(final LeaStudent arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 Create 】- 开始运行 ");

		final String query = "INSERT INTO lea_student (acct_id, bunch_id, apply_date, locked) VALUES"
				+ " (:acctId, :bunchId, :applyDate, :locked)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 Create 】- 完成运行 ");
		return index;

	}
	
	@Override
	public LeaStudent queryByAcctBunch(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 queryByAcctBunch 】- 开始运行 ");

		final String query = "SELECT * FROM lea_student WHERE acct_id = :acctId AND bunch_id = :bunchId";
		logger.debug(" 数据库执行语句为 " + query);

		LeaStudent entity = queryObject(query, LeaStudent.class, map);

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 queryByAcctBunch 】- 完成运行 ");
		return entity;

	}

	

	@Override
	public LeaStudent queryByAcctMajor(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 queryByAcctMajor 】- 开始运行 ");

		final String query = "SELECT a.* FROM lea_student AS a, lea_bunch AS b, lea_term AS c WHERE a.bunch_id = b.id"
				+ " AND b.term_id = c.id AND c.major_id = :majorId AND a.acct_id = :acctId";
		logger.debug(" 数据库执行语句为 " + query);

		LeaStudent entity = queryObject(query, LeaStudent.class, map);

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 queryByAcctMajor 】- 完成运行 ");
		return entity;

	}

	@Override
	public LeaStudent queryByAcctTerm(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 queryByAcctTerm 】- 开始运行 ");

		final String query = "SELECT a.* FROM lea_student AS a, lea_bunch AS b, lea_term AS c WHERE a.bunch_id = b.id"
				+ " AND b.term_id = c.id AND c.id = :termId AND a.acct_id = :acctId";
		logger.debug(" 数据库执行语句为 " + query);

		LeaStudent entity = queryObject(query, LeaStudent.class, map);

		logger.debug(" 【 Dao 】-【 LeaStudentDao 】-【 queryByAcctTerm 】- 完成运行 ");
		return entity;

	}

}
